// pages/mine/mine.js
import { URL, SER_KEY } from "../../config.js"
import { POST, GET } from "../../utils/request.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabData: [{
      id: 0,
      name: "待付款",
      imgUrl: '../../images/dfk.png'
    }, {
      id: 1,
      name: "待接单",
      imgUrl: '../../images/untaking_gray.png'
    }, {
      id: 2,
      name: "待发货",
      imgUrl: '../../images/dfh.png'
    }, {
      id: 3,
      name: "待收货",
      imgUrl: '../../images/dsh.png'
    }, {
      id: 4,
      name: "已完成",
      imgUrl: '../../images/ywc.png'

    }, {
      id: 5,
      name: "退款",
      imgUrl: '../../images/tk.png'
    }],
    userMsg:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  getUserById() {
    let that = this;
    let url = URL.HTTP_BASE_INTRANET + SER_KEY.SER_KEY14;
    let data = {
      appid: getApp().globalData.appId,
      sessionId: wx.getStorageSync('session_id')
    };
    GET(url, data, (ret) => {
      if (ret.statusCode == 200) {
        wx.stopPullDownRefresh()
        // console.log(ret.data.person)
        let msg = ret.data.person
        let phone=msg.phone
        var reg = /^(\d{3})(\d{4})(\d{4})$/;
        var matches = reg.exec(phone);
        var newNum = matches[1] + ' ' + matches[2] + ' ' + matches[3];
        console.log(newNum)
        that.setData({
          userMsg: msg,
          'userMsg.phone':newNum
        })
      } else {
        wx.showToast({
          title: '数据走丢啦，请稍后再试',
          icon: 'none'
        });
      }
    })
  },
  toOrders(){
    wx.switchTab({
      url: '../orders/orders',
    })
  },
  chooseTab(e){
    let id = e.currentTarget.id
    getApp().globalData.tabId=id
    console.log(id)
    wx.switchTab({
      url: '../orders/orders',
    })
  },
  loginOut(){
    let that=this
    wx.showModal({
      title: '提示',
      content: '是否确认退出账号？',
      cancelText: "否",
      confirmText: "是",
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          that.setData({
            userMsg:{
              money:0,
              integral:0,
              order_count:0
            }
          })
          wx.removeStorageSync('session_id');
        }
      },
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getUserById()
  },
  newStore(){
    wx.showToast({
      title: '该功能暂未开放',
      icon:'none'
    })
  },
  //微信登录
  bindGetUserInfo: function (e) {
    wx.navigateTo({
      url: '../authorized-login/authorized-login',
    })
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getUserById()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})